<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="css/fdj&gw.css" />
  </head>
  <body>
    <ul>
      <li>
        <div class="box">
          <div class="box1">
            <h1>
              美国原装进口lnstinct生鲜本能百利猫粮/生鲜系列 无谷鸡肉配方全猫粮
              10磅(4.5kg)
            </h1>
            <p>
              中国B2C平台合作伙伴 高蛋白 易消化 2种颗粒 生熟同享 冻干生鲜肉粒
              营养兼美味
            </p>
          </div>

          <div class="box2">
            <div id="zoomBox">
              <div id="midArea">
                <img src="img/f1.jpg" />
                <div id="zoom"></div>
              </div>
              <div id="bigArea">
                <img src="img/f1.jpg" />
              </div>
              <div id="smallArea">
                <img src="img/f1.jpg" />
                <img src="img/f2.jpg" />
                <img src="img/f3.jpg" />
                <img src="img/f4.jpg" />
              </div>
            </div>
          </div>

          <div class="box3">
            <div class="b1">
              <p>此商品参与"换季无忧 品质优惠" 活动</p>
              <div class="b2">
                <p>距离活动结束还剩:</p>
                <p id="box"></p>
              </div>
            </div>

            <div class="box4">
              <p class="b3">￥448.00</p>
              <p class="b4">E宠价:￥638.00</p>
            </div>
            <input type="button" value="加入购物车" class="btn" />
          </div>
        </div>
      </li>
    </ul>
    <a href=""></a>
    <script src="js/cart.js"></script>
    <script>
      //取数据
      let productDatas = JSON.parse(localStorage.getItem("productDatas"));
      //渲染，生成结构
      let oUl = document.getElementsByClassName("ul");
      let html = "";
      productDatas.forEach((item) => {
        html += `
        <li>
            <a href='detail.html?pid=${item.id}'>
            <img src="${item.img / imgsrc}" />
            </a>
            <h1>${item.pname}</h1>
            <p class="b3">${item.pprice}</p>
            <input type="button" value="加入购物车" data-id="${
              item.id
            }"  class="btn"/>
            </li>
          `;
      });

      oUl.innerHTML = html;

      //购物车数据cartDatas {1:5,2:3,3:10}  一个id对应一个数量
      let cart = new Cart();
      let aBtns = document.querySelectorAll(".btn");
      aBtns.forEach((item) => {
        item.onclick = () => {
          let pid = item.getAttribute("data-id");
          console.log(pid);
          cart.saveData(pid);
        };
      });
    </script>
    <script src="js/f放大镜.js"></script>
    <script src="js/f倒计时.js"></script>
  </body>
</html>
